<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'cookie.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  <%
  String username="";
  int visitCount=0;                 //访问次数
  	Cookie[]cookies=request.getCookies();            //服务器发送cookie后，客户端获取传过来的cookies
  	for(Cookie c:cookies){
  		out.println(c.getName());
  		//out.println(c.getValue()+"<br/>");
  		out.println(URLDecoder.decode(c.getValue(),"UTF-8"));  //用utf-8解码
  		if("user".equals(c.getName())){       //getname是获得key的名字
      		username=URLDecoder.decode(c.getValue(),"utf-8");
  		}
  		if("visit".equals(c.getName())){
  		visitCount=Integer.parseInt(c.getValue());
  		visitCount++;
  		}
  	}
  	
  	//cookie可以用base64编码保存二进制文件
  	//cookie修改就是新建cookie的key值与原cookie的key值相同
  	//删除则只需把cookie 的maxAge设置为0即可
  	Cookie visitC=new Cookie("visit",visitCount+"");  //把登录次数
  	response.addCookie(visitC);
   %>
  <body>.<center>登录信息</center>
  <div style="border: solid;color: red;width: 500px;height: 100px;" >
  	您的账号：<%=username %>
  	登陆次数:<%=visitCount %>
  	${time}
  </div>
  
  <%=new Date(session.getCreationTime()) %>   <!-- session创建时间 -->
  <br/>
  <%=new Date() %>           <!-- 当前时间 -->
    <a href="<%=response.encodeUrl("index.jsp") %>">url重写</a>
  </body>
</html>
